import Vue from 'vue'
Vue.filter('setTime', function (value) {//setTime为过滤器名
//	console.log(new Date(value));
  if(value == null){
    return "未知";
  }
  let oldDate = new Date(value);
  let newDate = new Date();
  var dayNum = "";
  var getTime = (newDate.getTime()-oldDate.getTime())/1000;
//  console.log(getTime);
  if(getTime < 60*5){
    dayNum = "刚刚";
  }else if(getTime >= 60*5 && getTime < 60*60){
    dayNum = parseInt(getTime / 60) + "分钟前";
  }else if(getTime >= 3600 && getTime < 3600*24){
    dayNum = parseInt(getTime / 3600) + "小时前";
  }else if(getTime >= 3600 * 24 && getTime < 3600 * 24 * 30) {
    dayNum = parseInt(getTime / 3600 / 24) + "天前";
  }
  else{
    let year   = oldDate.getFullYear();
    let month  = oldDate.getMonth()+1;
    let day    = oldDate.getDate();
    return dayNum+" "+year+"-"+month+"-"+day;
  }

  return dayNum;
});